package com.itheima.mytext10;

public class Foodie extends Thread{//吃货

    @Override
    public void run() {
        while (true)
        {
            synchronized (Desk.obj)
            {
                if(Desk.count==0)
                    break;
                else
                {
                    if(Desk.foodflag==0)//没有面条了，需要等待厨师
                    {
                        try {
                            Desk.obj.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                    else
                    {
                        //有面条了吃货可以吃，吃完了就要求厨师继续做
                        Desk.count--;
                        System.out.println("吃货正在吃面条，还剩下"+Desk.count+"碗");
                         Desk.foodflag=0;//表示当前面条被吃完
                        Desk.obj.notifyAll();//唤醒厨师做面条
                    }
                }
            }
        }
    }
}
